<?php 
require 'header.php';
if(!isset($_POST['submit']))
{

$query="SELECT name FROM branch";
$result=mysqli_query ($con, $query);

?>
<form action="" method="post"> <!--form to add new employees -->
        <table>
             <tr>
                <td>Access Level:</td>
            </tr>
            <tr>
                <td><select name="level">
                        <option value="manager">Manager</option>
                        <option value="sales">Sales</option>
                    </select></td>
            </tr>
            <tr>
                <td>Name:</td>
            </tr>
            <tr>
                <td><input type="text" name="name" value=""></td>
            </tr>
			<tr>
                <td>Department:</td>
            </tr>
            <tr>
                <td><input type="text" name="department" value=""></td>
            </tr>
			<tr>
                <td>Password:</td>
            </tr>
            <tr>
                <td><input type="password" name="password" value=""></td>
            </tr>
			<tr>
                <td>Hourly Salary:</td>
            </tr>
			<tr>
                <td><input type="text" name="salary" value=""></td>
            </tr>
			<tr>
				<tr>
            <td>Branch:</td>
            </tr>
			<tr>
                <td><select name="branch">
                        <?php
						 while($branch = mysqli_fetch_array($result))
                            echo "<option  value=$branch[name]>$branch[name]</option>";
                        
					
						?>
                    </select></td>
            </tr>
		      
        
            <tr>
                <td><input type="submit" name="submit" value="Add Employee"></td>
            </tr>

        </table>
    </form>
	<?php
	} else
	{
	//Connect to the database.
	$query = "INSERT INTO employee ( access_level, employee_name, department, password, hourly_salary,monthly_hours, branch) VALUES ( '$_POST[level]','$_POST[name]','$_POST[department]','$_POST[password]','$_POST[salary]',0, '$_POST[branch]')";
	if (!mysqli_query($con,$query))
	{
	die('Error: ' . mysqli_error($con));
	}
		
	}
	require 'footer.php';					
	?>
	
